#pragma once
#include "Tcpservice.hpp"
#include"Operation.hpp"
#include"Task.hpp"
#include"ThreadPool.hpp"
class Httpservice
{
public:
    Httpservice(uint16_t port)
        : _port(port)
    {
    }
    void Init()
    {
        _tptr = Tcpservice::getTcpservice(_port);
    }
    void Start()
    {
        // accept
        struct sockaddr_in client;
        socklen_t len = sizeof(client);
        while (true)
        {
            int sock = accept(_tptr->Sock(), (sockaddr *)&client, &len);
            if (sock < 0)
            {
                continue;
            }
            // //进行处理请求；
            // pthread_t tid;
            // //进行多线程处理；
            // int*ptr = new int(sock);
            // pthread_create(&tid,nullptr,Operation::Handler,ptr);
            // pthread_detach(tid);//线程分离；
            //用线程池处理；
            //构建一个任务，扔给线程池自己处理；
            std::cout<<"创建任务"<<std::endl;
            Task task(sock);
            ThreadPool<Task>::getThreadPool()->push(task);
        }
    }

private:
    uint16_t _port;
    Tcpservice *_tptr;
};